export default {
  props: {
    data: {
      type: Object,
      default: () => {}
    },

    loading: {
      type: Boolean,
      default: false
    }
  },

  emits: ['close', 'confirm', 'update:loading'],

  data(props) {
    return {
      pageData: props.data,
      requestLoading: props.loading
    };
  },

  watch: {
    loading() {
      this.requestLoading = this.loading;
    },

    requestLoading() {
      this.$emit('update:loading', this.requestLoading);
    }
  },

  methods: {
    close() {
      this.$emit('close');
    },

    confirm() {
      const pageData = this.pageData;
      this.$emit('confirm', pageData);
    },

    doSubmit() {
      return new Promise((resolve) => {
        resolve();
      });
    },

    submit() {
      this.requestLoading = true;
      this.doSubmit().then(() => {
        this.confirm();
      }).finally(() => {
        this.requestLoading = false;
      });
    }
  }
};
